﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ApplLogic.ApplClasses;
using TCPClient.UI.LogicForUserControls;
using TCPClient.UI.UserControls;

namespace TCPClient.UI
{
    public partial class SpecialRequestsOfWorkerForm : Form
    {
        private ScMainUserControl m_MainUserControlRef = null;
        public SpecialRequestsOfWorkerForm(UserControl userControl)
        {
            InitializeComponent();
            m_MainUserControlRef = userControl as ScMainUserControl;
        }

        private void linkLabelWorkAllTheWeek_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            List<ShiftRequestFromGUI> requests = new List<ShiftRequestFromGUI>();
            foreach (var dayInWeek in m_MainUserControlRef.WeekTableUserControl.Days)
            {
                foreach (var shiftInDay in dayInWeek.ShiftsInDay)
                {
                    requests.Add(new ShiftRequestFromGUI()
                    {
                        EndDate = shiftInDay.EndTime,
                        StartDate = shiftInDay.StartTime,
                        Type = eType.WANTED
                    });
                }
            }
            ScMainUserControlLogic.Instance.UpdateServerWithWorkerRequest(requests);
            m_MainUserControlRef.RefreshAll();
            this.Close();
        }

        private void linkLabelNotAbleToWork_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            List<ShiftRequestFromGUI> requests = new List<ShiftRequestFromGUI>();
            foreach (var dayInWeek in m_MainUserControlRef.WeekTableUserControl.Days)
            {
                foreach (var shiftInDay in dayInWeek.ShiftsInDay)
                {
                    requests.Add(new ShiftRequestFromGUI()
                    {
                        EndDate = shiftInDay.EndTime,
                        StartDate = shiftInDay.StartTime,
                        Type = eType.FORBIDDEN
                    });
                }
            }
            ScMainUserControlLogic.Instance.UpdateServerWithWorkerRequest(requests);
            m_MainUserControlRef.RefreshAll();
            this.Close();
        }

        private void linkLabelOneShiftInDay_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            List<ShiftRequestFromGUI> requests = new List<ShiftRequestFromGUI>();
            Random rand = new Random();
            foreach (var dayInWeek in m_MainUserControlRef.WeekTableUserControl.Days)
            {
                int shiftNum = rand.Next(0, 3);
                requests.Add(new ShiftRequestFromGUI()
                {
                    EndDate = dayInWeek.ShiftsInDay[shiftNum].EndTime,
                    StartDate = dayInWeek.ShiftsInDay[shiftNum].StartTime,
                    Type = eType.WANTED
                });
            }
            ScMainUserControlLogic.Instance.UpdateServerWithWorkerRequest(requests);
            m_MainUserControlRef.RefreshAll();
            this.Close();
        }

        private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            List<ShiftRequestFromGUI> requests = new List<ShiftRequestFromGUI>();
            Random rand = new Random();
            foreach (var dayInWeek in m_MainUserControlRef.WeekTableUserControl.Days)
            {
                int shiftNum = rand.Next(0, 2);
                requests.Add(new ShiftRequestFromGUI()
                {
                    EndDate = dayInWeek.ShiftsInDay[shiftNum].EndTime,
                    StartDate = dayInWeek.ShiftsInDay[shiftNum].StartTime,
                    Type = eType.WANTED
                });
                requests.Add(new ShiftRequestFromGUI()
                {
                    EndDate = dayInWeek.ShiftsInDay[shiftNum + 1].EndTime,
                    StartDate = dayInWeek.ShiftsInDay[shiftNum + 1].StartTime,
                    Type = eType.WANTED
                });


            }
            ScMainUserControlLogic.Instance.UpdateServerWithWorkerRequest(requests);
            m_MainUserControlRef.RefreshAll();
            this.Close();
        }

        private void buttonQAvail_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox1.AppendText("Worker is available to work during all week.\n");
            textBox1.AppendText("By choosing this option all shifts will be marked as wanted.\n");
        }

        private void buttonQ1EachDay_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox1.AppendText("Worker is available to work on one shift in each day during the week.\n");
            textBox1.AppendText("By choosing this option one shiht in each day will be marked as wanted.\n");
        }

        private void buttonQCant_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox1.AppendText("Worker is not available to work during all week.\n");
            textBox1.AppendText("By choosing this option all shifts will be marked as forbidden.\n");
        }

        private void buttonQ2InRow_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox1.AppendText("Worker is available to work on two shift in a row on each day during the week.\n");
            textBox1.AppendText("By choosing this option two shift in a row on each day will be marked as wanted.\n");
        }
    }
}
